import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HorizontalDash extends StatelessWidget {
  final double height;
  final double width;
  final Color color;

  HorizontalDash({this.width, this.height = 1, this.color = Colors.black});

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, constraints) {
      var finalWidth;
      if (width == null) {
        finalWidth = constraints.biggest.width;
      } else {
        finalWidth = width < constraints.biggest.width
            ? width
            : constraints.biggest.width;
      }

      final dashWidth = 2.0;
      final dashCount = (finalWidth / dashWidth).floor();

      return Flex(
        direction: Axis.horizontal,
        children: List.generate(dashCount, (index) {
          return SizedBox(
            width: dashWidth,
            height: height,
            child: DecoratedBox(
              decoration: BoxDecoration(
                  color: index % 2 == 0 ? Colors.transparent : color),
            ),
          );
        }),
      );
    });
  }
}
